#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

//尽量选得分高，年龄也大的
bool compare(vector<int> A,vector<int> B){
    if(A[1]==B[1]){
        return A[0]<B[0];
    }
    return A[1]<B[1];
}

class Solution {
public:
    int bestTeamScore(vector<int>& scores, vector<int>& ages) {
        if(scores.size()==1){
            return scores[0];
        }
        vector<vector<int>> SA;
        for(int i = 0;i<scores.size();++i){
            SA.push_back({scores[i],ages[i]});
        }
        sort(SA.begin(),SA.end(),compare);
        vector<int> dp(scores.size(),0);
        for(int i = 0;i<scores.size();++i){
            for(int j = i-1;j>=0;--j){
                if(SA[j][0]<=SA[i][0]){
                    dp[i] = max(dp[i],dp[j]);
                }
            }
            dp[i] += SA[i][0];
        }
        return *max_element(dp.begin(),dp.end());
    }
};

int main(){
    Solution S;
    vector<int> scores = {1,3,5,10,15};
    vector<int> ages = {1,2,3,4,5};
    cout<<S.bestTeamScore(scores,ages)<<endl;
}